package com.javaobj.auth.security.jwt;

import com.javaobj.auth.accesstoken.AccessTokenService;
import com.javaobj.auth.config.AuthConfigurationProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConditionalOnProperty(value = "com.javaobj.auth.jwt.key-value")
@EnableConfigurationProperties(AuthConfigurationProperties.class)
@Configuration
public class JwtWebSecurityConfiguration {


    /**
     * 创建一个 {@link JWTAccessTokenService}
     * @param properties
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public AccessTokenService accessTokenService(AuthConfigurationProperties properties){
        return new JWTAccessTokenService(properties.getJwt().getKeyValue(), properties.getJwt().getAlgorithm());
    }


}
